package com.itheima.advantagesup.utils;

import com.itheima.advantagesup.vo.MenuVO;

import java.util.ArrayList;
import java.util.List;

public class MenuUtils {
    public static List<MenuVO> getMenuVOList(List<MenuVO> menuVOList){
        List<MenuVO> list=new ArrayList<>();
        for (MenuVO menuVO : menuVOList) {
            if(menuVO.getPid()==0){
                list.add(findChildren(menuVO,menuVOList));
            }
        }
        return list;
    }
    public static MenuVO findChildren(MenuVO menuVO,List<MenuVO> menuVOList){
        for (MenuVO vo : menuVOList) {
            if(menuVO.getId().equals(vo.getPid())){
                if(menuVO.getChildren()==null){
                    menuVO.setChildren(new ArrayList<MenuVO>());
                }
                menuVO.getChildren().add(findChildren(vo,menuVOList));
            }
        }
        return menuVO;
    }
}
